$(function() {
  // 响应式视频
  $("embed,object").parent().addClass("embed-responsive embed-responsive-4by3");
  // 侧栏跟随
  let $sidebar = $("aside.sidebar .widget:last-of-type"),
    offsetTop = 0,
    // copyTop = 0,
    scrollt = 0;
  $(window).scroll(function() {
    if ($sidebar.length === 0) return;
    scrollt = $(window).scrollTop();
    if (scrollt >= 137) {
      $("#fixed-box,.backTop").addClass("is-active");
    } else {
      $("#fixed-box,.backTop").removeClass("is-active");
    }
    // console.log(scrollt);
    if ($(window).width() < 768) return false;
    if (offsetTop == 0) {
      offsetTop = $sidebar.offset().top;
    }
    let copyTopN = $(".footer").offset().top;
    if (scrollt + $sidebar.outerHeight() > copyTopN - 137) {
      let marTop = parseInt($sidebar.css("marginTop"));
      let rdyTop = copyTopN - offsetTop - $sidebar.outerHeight() - 137;
      $sidebar.stop().animate({
        marginTop: marTop > rdyTop ? marTop : rdyTop,
      });
      return false;
    }
    if (scrollt > offsetTop) {
      $sidebar.stop().animate({
        marginTop: scrollt - offsetTop + 45,
      });
    } else {
      $sidebar.stop().animate({
        marginTop: 15,
      });
    }
    return false;
  });
  $(".backTop").click(function() {
    return (
      $("html,body")
        .animate(
          {
            scrollTop: "0px",
          },
          500,
        )
        .fadeIn(),
      !1
    );
  });
});
;/* ========================================================================
 * Bootstrap: collapse.js v3.4.1
 * https://getbootstrap.com/docs/3.4/javascript/#collapse
 * ========================================================================
 * Copyright 2011-2019 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ======================================================================== */

/* jshint latedef: false */

+function($) {
  "use strict";

  // COLLAPSE PUBLIC CLASS DEFINITION
  // ================================

  var Collapse = function(element, options) {
    this.$element      = $(element);
    this.options       = $.extend({}, Collapse.DEFAULTS, options);
    this.$trigger      = $("[data-toggle=\"collapse\"][href=\"#" + element.id + "\"]," +
                           "[data-toggle=\"collapse\"][data-target=\"#" + element.id + "\"]");
    this.transitioning = null;

    if (this.options.parent) {
      this.$parent = this.getParent();
    } else {
      this.addAriaAndCollapsedClass(this.$element, this.$trigger);
    }

    if (this.options.toggle) this.toggle();
  };

  Collapse.VERSION  = "3.4.1";

  Collapse.TRANSITION_DURATION = 350;

  Collapse.DEFAULTS = {
    toggle: true,
  };

  Collapse.prototype.dimension = function() {
    var hasWidth = this.$element.hasClass("width");
    return hasWidth ? "width" : "height";
  };

  Collapse.prototype.show = function() {
    if (this.transitioning || this.$element.hasClass("in")) return;

    var activesData;
    var actives = this.$parent && this.$parent.children(".panel").children(".in, .collapsing");

    if (actives && actives.length) {
      activesData = actives.data("bs.collapse");
      if (activesData && activesData.transitioning) return;
    }

    var startEvent = $.Event("show.bs.collapse");
    this.$element.trigger(startEvent);
    if (startEvent.isDefaultPrevented()) return;

    if (actives && actives.length) {
      Plugin.call(actives, "hide");
      activesData || actives.data("bs.collapse", null);
    }

    var dimension = this.dimension();

    this.$element
      .removeClass("collapse")
      .addClass("collapsing")[dimension](0)
      .attr("aria-expanded", true);

    this.$trigger
      .removeClass("collapsed")
      .attr("aria-expanded", true);

    this.transitioning = 1;

    var complete = function() {
      this.$element
        .removeClass("collapsing")
        .addClass("collapse in")[dimension]("");
      this.transitioning = 0;
      this.$element
        .trigger("shown.bs.collapse");
    };

    if (!$.support.transition) return complete.call(this);

    var scrollSize = $.camelCase(["scroll", dimension].join("-"));

    this.$element
      .one("bsTransitionEnd", $.proxy(complete, this))
      .emulateTransitionEnd(Collapse.TRANSITION_DURATION)[dimension](this.$element[0][scrollSize]);
  };

  Collapse.prototype.hide = function() {
    if (this.transitioning || !this.$element.hasClass("in")) return;

    var startEvent = $.Event("hide.bs.collapse");
    this.$element.trigger(startEvent);
    if (startEvent.isDefaultPrevented()) return;

    var dimension = this.dimension();

    this.$element[dimension](this.$element[dimension]())[0].offsetHeight;

    this.$element
      .addClass("collapsing")
      .removeClass("collapse in")
      .attr("aria-expanded", false);

    this.$trigger
      .addClass("collapsed")
      .attr("aria-expanded", false);

    this.transitioning = 1;

    var complete = function() {
      this.transitioning = 0;
      this.$element
        .removeClass("collapsing")
        .addClass("collapse")
        .trigger("hidden.bs.collapse");
    };

    if (!$.support.transition) return complete.call(this);

    this.$element
      [dimension](0)
      .one("bsTransitionEnd", $.proxy(complete, this))
      .emulateTransitionEnd(Collapse.TRANSITION_DURATION);
  };

  Collapse.prototype.toggle = function() {
    this[this.$element.hasClass("in") ? "hide" : "show"]();
  };

  Collapse.prototype.getParent = function() {
    return $(document).find(this.options.parent)
      .find("[data-toggle=\"collapse\"][data-parent=\"" + this.options.parent + "\"]")
      .each($.proxy(function(i, element) {
        var $element = $(element);
        this.addAriaAndCollapsedClass(getTargetFromTrigger($element), $element);
      }, this))
      .end();
  };

  Collapse.prototype.addAriaAndCollapsedClass = function($element, $trigger) {
    var isOpen = $element.hasClass("in");

    $element.attr("aria-expanded", isOpen);
    $trigger
      .toggleClass("collapsed", !isOpen)
      .attr("aria-expanded", isOpen);
  };

  function getTargetFromTrigger($trigger) {
    var href;
    var target = $trigger.attr("data-target")
      || (href = $trigger.attr("href")) && href.replace(/.*(?=#[^\s]+$)/, ""); // strip for ie7

    return $(document).find(target);
  }


  // COLLAPSE PLUGIN DEFINITION
  // ==========================

  function Plugin(option) {
    return this.each(function() {
      var $this   = $(this);
      var data    = $this.data("bs.collapse");
      var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == "object" && option);

      if (!data && options.toggle && /show|hide/.test(option)) options.toggle = false;
      if (!data) $this.data("bs.collapse", (data = new Collapse(this, options)));
      if (typeof option == "string") data[option]();
    });
  }

  var old = $.fn.collapse;

  $.fn.collapse             = Plugin;
  $.fn.collapse.Constructor = Collapse;


  // COLLAPSE NO CONFLICT
  // ====================

  $.fn.collapse.noConflict = function() {
    $.fn.collapse = old;
    return this;
  };


  // COLLAPSE DATA-API
  // =================

  $(document).on("click.bs.collapse.data-api", "[data-toggle=\"collapse\"]", function(e) {
    var $this   = $(this);

    if (!$this.attr("data-target")) e.preventDefault();

    var $target = getTargetFromTrigger($this);
    var data    = $target.data("bs.collapse");
    var option  = data ? "toggle" : $this.data();

    Plugin.call($target, option);
  });

}(jQuery);
;/* ========================================================================
 * Bootstrap: dropdown.js v3.4.1
 * https://getbootstrap.com/docs/3.4/javascript/#dropdowns
 * ========================================================================
 * Copyright 2011-2019 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ======================================================================== */


+function($) {
  "use strict";

  // DROPDOWN CLASS DEFINITION
  // =========================

  var backdrop = ".dropdown-backdrop";
  var toggle   = "[data-toggle=\"dropdown\"]";
  var Dropdown = function(element) {
    $(element).on("click.bs.dropdown", this.toggle);
  };

  Dropdown.VERSION = "3.4.1";

  function getParent($this) {
    var selector = $this.attr("data-target");

    if (!selector) {
      selector = $this.attr("href");
      selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, ""); // strip for ie7
    }

    var $parent = selector !== "#" ? $(document).find(selector) : null;

    return $parent && $parent.length ? $parent : $this.parent();
  }

  function clearMenus(e) {
    if (e && e.which === 3) return;
    $(backdrop).remove();
    $(toggle).each(function() {
      var $this         = $(this);
      var $parent       = getParent($this);
      var relatedTarget = { relatedTarget: this };

      if (!$parent.hasClass("open")) return;

      if (e && e.type == "click" && /input|textarea/i.test(e.target.tagName) && $.contains($parent[0], e.target)) return;

      $parent.trigger(e = $.Event("hide.bs.dropdown", relatedTarget));

      if (e.isDefaultPrevented()) return;

      $this.attr("aria-expanded", "false");
      $parent.removeClass("open").trigger($.Event("hidden.bs.dropdown", relatedTarget));
    });
  }

  Dropdown.prototype.toggle = function(e) {
    var $this = $(this);

    if ($this.is(".disabled, :disabled")) return;

    var $parent  = getParent($this);
    var isActive = $parent.hasClass("open");

    clearMenus();

    if (!isActive) {
      if ("ontouchstart" in document.documentElement && !$parent.closest(".navbar-nav").length) {
        // if mobile we use a backdrop because click events don't delegate
        $(document.createElement("div"))
          .addClass("dropdown-backdrop")
          .insertAfter($(this))
          .on("click", clearMenus);
      }

      var relatedTarget = { relatedTarget: this };
      $parent.trigger(e = $.Event("show.bs.dropdown", relatedTarget));

      if (e.isDefaultPrevented()) return;

      $this
        .trigger("focus")
        .attr("aria-expanded", "true");

      $parent
        .toggleClass("open")
        .trigger($.Event("shown.bs.dropdown", relatedTarget));
    }

    return false;
  };

  Dropdown.prototype.keydown = function(e) {
    if (!/(38|40|27|32)/.test(e.which) || /input|textarea/i.test(e.target.tagName)) return;

    var $this = $(this);

    e.preventDefault();
    e.stopPropagation();

    if ($this.is(".disabled, :disabled")) return;

    var $parent  = getParent($this);
    var isActive = $parent.hasClass("open");

    if (!isActive && e.which != 27 || isActive && e.which == 27) {
      if (e.which == 27) $parent.find(toggle).trigger("focus");
      return $this.trigger("click");
    }

    var desc = " li:not(.disabled):visible a";
    var $items = $parent.find(".dropdown-menu" + desc);

    if (!$items.length) return;

    var index = $items.index(e.target);

    if (e.which == 38 && index > 0)                 index--;         // up
    if (e.which == 40 && index < $items.length - 1) index++;         // down
    if (!~index)                                    index = 0;

    $items.eq(index).trigger("focus");
  };


  // DROPDOWN PLUGIN DEFINITION
  // ==========================

  function Plugin(option) {
    return this.each(function() {
      var $this = $(this);
      var data  = $this.data("bs.dropdown");

      if (!data) $this.data("bs.dropdown", (data = new Dropdown(this)));
      if (typeof option == "string") data[option].call($this);
    });
  }

  var old = $.fn.dropdown;

  $.fn.dropdown             = Plugin;
  $.fn.dropdown.Constructor = Dropdown;


  // DROPDOWN NO CONFLICT
  // ====================

  $.fn.dropdown.noConflict = function() {
    $.fn.dropdown = old;
    return this;
  };


  // APPLY TO STANDARD DROPDOWN ELEMENTS
  // ===================================

  $(document)
    .on("click.bs.dropdown.data-api", clearMenus)
    .on("click.bs.dropdown.data-api", ".dropdown form", function(e) { e.stopPropagation(); })
    .on("click.bs.dropdown.data-api", toggle, Dropdown.prototype.toggle)
    .on("keydown.bs.dropdown.data-api", toggle, Dropdown.prototype.keydown)
    .on("keydown.bs.dropdown.data-api", ".dropdown-menu", Dropdown.prototype.keydown);

}(jQuery);
